<template>
	<view class="items">
		<view class="item">
			<view class="top" v-if="info.userInfo">
				<u-avatar :src="info.userInfo.avatar"></u-avatar>
				<view class="" style="flex: 1;margin-left: 20rpx;">
					<view class="" v-if="info.userInfo">
						{{info.userInfo.username || "--"}}
					</view>
					<view class="" style="color: #7B7878;font-size: 24rpx;">
						{{formatTimestamp(info.createtime)}}
					</view>
				</view>
				<view class="">

				</view>
			</view>
			<view class="" style="margin: 10rpx 0;">
				{{info.title}}
			</view>
			<view class="imgs" >
				<image :src="img" mode="" v-for="(img,ind) in info.images" :key="ind"></image>
			</view>
			<view class=""
				style="display: flex;align-items: center;justify-content: space-between;margin-top: 20rpx;color: #656565;">
				<view class="" style="display: flex;align-items: center;">
					<u-icon name="eye" color="#656565" size="22"></u-icon>
					<text style="margin-left: 6rpx;">浏览 {{info.view}}</text>
				</view>
				<view class="">
					收藏 {{info.collect}}
				</view>
			</view>
		</view>
		<view class="footer">
			<view class="" style="display: flex;color: #646464;opacity: 0;">
				<view class="" style="display: flex;flex-direction: column;align-items: center;margin-right: 40rpx;">
					<u-icon name="star" color="#646464" size="26"></u-icon>
					<text style="margin-top: 6rpx;color: #646464;">收藏</text>
				</view>
				<view class="" style="display: flex;flex-direction: column;align-items: center;margin-right: 20rpx;">
					<u-icon name="phone" color="#646464" size="26"></u-icon>
					<text style="margin-top: 6rpx;color: #646464;">电话</text>
				</view>
			</view>
			<view class="btn" @click="del">
				删除贴子
			</view>
		</view>
	</view>
</template>

<script>
	import {
		delInfo
	} from "@/request/api/tiezi.js"
	export default {
		data() {
			return {
				info: {}
			}
		},
		onLoad(opt) {
			this.info = JSON.parse(opt.item);
		},
		methods: {
			formatTimestamp(timestamp) {
				// 创建 Date 对象
				const date = new Date(timestamp * 1000); // 将时间戳转换为毫秒

				// 获取年份、月份、日期、小时、分钟、秒
				const year = date.getFullYear();
				const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始，需要加1
				const day = String(date.getDate()).padStart(2, '0');
				const hour = String(date.getHours()).padStart(2, '0');
				const minute = String(date.getMinutes()).padStart(2, '0');
				const second = String(date.getSeconds()).padStart(2, '0');

				// 返回格式化的日期时间字符串
				return `${year}-${month}-${day}`;
			},
			del() {
				let that = this;
				uni.showModal({
					title: '提示',
					content: '确认删除此贴？',
					success: function(res) {
						if (res.confirm) {
							delInfo({
								info_id: that.info.id
							}).then(res => {
								uni.reLaunch({
									url: "/pages/my/my"
								})
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});

			},
		}
	}
</script>
<style>
	page {
		height: 100%;
		overflow: auto;
	}
</style>
<style scoped lang="scss">
	.footer {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100vw;
		max-width: 100vw;
		display: flex;
		align-items: center;
		padding: 20rpx 30rpx;
		background-color: white;
		justify-content: space-between;
		box-sizing: border-box;

		.btn {
			background-color: #f36767;
			color: white;
			padding: 16rpx 30rpx;
			border-radius: 100px;
			font-size: 26rpx;
		}
	}


	.items {
		border-radius: 20rpx;
		padding: 30rpx;

		.item {
			border-radius: 20rpx;
			background-color: white;
			padding: 30rpx;
			margin-bottom: 20rpx;

			.top {
				display: flex;
				align-items: center;

				image {
					width: 80rpx;
					height: 80rpx;
					border-radius: 100px;
					margin-right: 20rpx;
				}

				.more {
					width: 40rpx;
					height: 10rpx;
					margin-right: 0;
				}
			}

			.imgs {
				display: flex;
				justify-content: space-between;
				flex-wrap: wrap;
				image {
					width: 190rpx;
					height: 190rpx;
					border-radius: 30rpx;
					margin-bottom: 10rpx;
				}
			}
		}
	}
</style>